package com.atguigu.educms.controller;


import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-01-01
 */
@RestController
@RequestMapping("/educms/banneradmin")

public class BannerAdminController {
    @Autowired
  private   CrmBannerService bannerService;

    //分页查询Banner
    @GetMapping("pageBanner/{page}/{limit}")
    public R  pageBanner(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> pageBanner = new Page<>(page, limit);
        IPage<CrmBanner> bannerIPage = bannerService.page(pageBanner, null);
        return R.ok().data("items",bannerIPage.getRecords()).data("total",bannerIPage.getTotal());
    }
    //添加Banner
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }
    @ApiOperation(value = "获取Banner")
    @GetMapping("get/{id}")
    public R get(@PathVariable String id) {
        CrmBanner banner = bannerService.getById(id);
        return R.ok().data("item", banner);
    }
    //删除Banner
    @DeleteMapping("delBanner/{id}")
    public R delBanner(@PathVariable String id){
        bannerService.removeById(id);
        return R.ok();
    }
    //修改Banner
    @PostMapping("updateBanner")
    public R updateBanner(@RequestBody CrmBanner crmBanner ){
        bannerService.updateById(crmBanner);
        return R.ok();
    }

}

